import yaml

from .singleton_decorator import singleton

@singleton
class SupportedModels:
    def __init__(self):
        self._models = None

    def initialize(self, models_file):
        with open(models_file, 'r') as f:
            models = yaml.safe_load(f)

        self._models = models

    def get(self, model_type):
        if self._models and model_type in self._models:
            return self._models[model_type]
        raise AttributeError(f"'{model_type}' Model is not currently supported. Comming soon!")

    def get_all_model_types(self):
        model_types = []
        for model_type in self._models.keys():
            model_types.append(model_type)
        return model_types
        
    def get_all_models(self):
        models = []
        for models_list in self._models.values():
            for model in models_list:
                models.append(model)
        return models